package top.likeqc.leetcode.editor.cn;

/**
 * @see <a href="https://leetcode.cn/problems/evaluate-boolean-binary-tree">2331. 计算布尔二叉树的值</a>
 */
public class EvaluateBooleanBinaryTree {
    public static void main(String[] args) {
        Solution solution = new EvaluateBooleanBinaryTree().new Solution();
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {}

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    // leetcode submit region begin(Prohibit modification and deletion)
    /**
     * Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode
     * right; TreeNode() {} TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left,
     * TreeNode right) { this.val = val; this.left = left; this.right = right; } }
     */
    class Solution {
        public static final int FALSE = 0;
        public static final int TRUE = 1;
        public static final int OR = 2;
        public static final int AND = 3;

        public boolean evaluateTree(TreeNode root) {
            if (root.left == null || root.right == null) {
                return root.val == TRUE;
            } else {
                if (root.val == OR) {
                    return evaluateTree(root.left) || evaluateTree(root.right);
                } else {
                    return evaluateTree(root.left) && evaluateTree(root.right);
                }
            }
        }
    }
    // leetcode submit region end(Prohibit modification and deletion)

}
